<?php

namespace App\Http\Controllers;

use App\Models\Article;
use App\Models\Site;
use Illuminate\Http\Request;

class SearchController extends Controller
{
    //
    public function index($action,$name)
    {
        if($action == 'site') {
            $sites  = Site::where('keywords','like','%'.$name.'%')->where(['state'=>1])->paginate(10);
            return view('search.site',compact('sites','action','name'));
        }
        if($action == 'article') {
            $sites  = Article::where('keywords','like','%'.$name.'%')->where(['state'=>1])->paginate(10);
            return view('search.article',compact('sites','action','name'));
        }
        return redirect('/', 301);
    }
}
